<script setup>
import { RouterLink } from 'vue-router'

// 定义组件的props，接收游戏热度榜数据
const props = defineProps({
  hotGames: {
    type: Array,
    default: () => []
  },
  title: {
    type: String,
    default: '游戏热度榜'
  },
  showMoreLink: {
    type: Boolean,
    default: true
  },
  moreLinkText: {
    type: String,
    default: '更多'
  },
  moreLinkHref: {
    type: String,
    default: '#'
  },
  showTopN: {
    type: Number,
    default: 5
  }
})
</script>

<template>
  <aside class="sidebar">
    <!-- 游戏热度排行榜 -->
    <div class="hot-games">
      <div class="section-header">
        <h3>{{ title }}</h3>
        <a v-if="showMoreLink" :href="moreLinkHref" class="more-link">{{ moreLinkText }}</a>
      </div>
      <div class="games-list-vertical">
        <div 
          v-for="(game, index) in hotGames.slice(0, showTopN)" 
          :key="game.id" 
          class="game-vertical-item"
        >
          <div 
            class="rank-number" 
            :class="{
              'top-three': index < 3,
              'rank-1': index === 0,
              'rank-2': index === 1,
              'rank-3': index === 2
            }"
          >
            {{ index + 1 }}
          </div>
          <div class="game-vertical-content">
            <img :src="game.image" :alt="game.name" class="game-vertical-thumbnail" />
            <RouterLink :to="`/game/${game.id}`" class="game-vertical-name">{{ game.name }}</RouterLink>
            <div class="game-popularity">
              <span class="popularity-text">热度 {{ game.popularity.toLocaleString() }}</span>
              <span class="change" :class="game.change.includes('+') ? 'up' : 'down'">{{ game.change }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </aside>
</template>

<style scoped>
/* 侧边栏样式 */
.sidebar {
  width: 300px;
  flex-shrink: 0;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  animation: sidebarFadeIn 0.5s ease;
}

.sidebar:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  position: relative;
}

.section-header h3 {
  font-size: 16px;
  margin: 0;
  color: #ffffff;
  transition: color 0.3s ease;
  position: relative;
  padding-bottom: 4px;
}

.section-header h3::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  background: #e6162d;
  transition: width 0.3s ease;
}

.sidebar:hover .section-header h3::after {
  width: 100%;
}

.sidebar:hover .section-header h3 {
  color: #e6162d;
}

.more-link {
  color: #999;
  text-decoration: none;
  font-size: 14px;
  transition: all 0.3s ease;
  position: relative;
  padding: 2px 8px;
  border-radius: 12px;
  overflow: hidden;
}

.more-link::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(230, 22, 45, 0.1), transparent);
  transition: left 0.5s ease;
}

.more-link:hover {
  color: #e6162d;
  background: rgba(230, 22, 45, 0.05);
}

.more-link:hover::before {
  left: 100%;
}

/* 游戏热度榜 - 竖向排列样式 */
.games-list-vertical {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.game-vertical-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all 0.3s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.game-vertical-item::before {
  content: '';
  position: absolute;
  left: -100%;
  top: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(230, 22, 45, 0.05), transparent);
  transition: left 0.5s ease;
}

.game-vertical-item:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateX(5px);
}

.game-vertical-item:hover::before {
  left: 100%;
}

/* 为列表项添加动画延迟 */
.game-vertical-item:nth-child(1) {
  animation: gameItemSlideIn 0.3s ease 0.1s forwards;
  opacity: 0;
  transform: translateX(-10px);
}

.game-vertical-item:nth-child(2) {
  animation: gameItemSlideIn 0.3s ease 0.2s forwards;
  opacity: 0;
  transform: translateX(-10px);
}

.game-vertical-item:nth-child(3) {
  animation: gameItemSlideIn 0.3s ease 0.3s forwards;
  opacity: 0;
  transform: translateX(-10px);
}

.game-vertical-item:nth-child(4) {
  animation: gameItemSlideIn 0.3s ease 0.4s forwards;
  opacity: 0;
  transform: translateX(-10px);
}

.game-vertical-item:nth-child(5) {
  animation: gameItemSlideIn 0.3s ease 0.5s forwards;
  opacity: 0;
  transform: translateX(-10px);
}

.game-vertical-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.game-vertical-thumbnail {
  width: 100%;
  height: auto;
  max-height: 120px;
  border-radius: 4px;
  object-fit: cover;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.game-vertical-item:hover .game-vertical-thumbnail {
  transform: scale(1.02);
  box-shadow: 0 2px 8px rgba(230, 22, 45, 0.2);
}

.game-vertical-name {
  font-size: 14px;
  font-weight: 500;
  color: #ffffff;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: all 0.3s ease;
  position: relative;
  padding-left: 4px;
}

.game-vertical-name::before {
  content: '→';
  position: absolute;
  left: -8px;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.game-vertical-item:hover .game-vertical-name {
  color: #e6162d;
  padding-left: 8px;
}

.game-vertical-item:hover .game-vertical-name::before {
  transform: translateX(4px);
  opacity: 1;
}

.rank-number {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background-color: rgba(255, 255, 255, 0.1);
  color: #999;
  font-size: 14px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.3s ease;
}

.rank-number.top-three {
  background-color: #fee7e9;
  color: #e6162d;
  box-shadow: 0 2px 4px rgba(230, 22, 45, 0.2);
}

.rank-number.rank-1 {
  background-color: #ffe188;
  color: #ff6b00;
  box-shadow: 0 2px 6px rgba(255, 225, 136, 0.4);
}

.rank-number.rank-2 {
  background-color: #d1e6ff;
  color: #3b82f6;
  box-shadow: 0 2px 6px rgba(209, 230, 255, 0.4);
}

.rank-number.rank-3 {
  background-color: #d1fae5;
  color: #10b981;
  box-shadow: 0 2px 6px rgba(209, 250, 229, 0.4);
}

.rank-number:hover {
  transform: scale(1.1);
}

.game-popularity {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}

.popularity-text {
  color: #999;
}

.change {
  font-weight: bold;
}

.change.up {
  color: #e6162d;
}

.change.down {
  color: #10b981;
}

/* 动画定义 */
@keyframes sidebarFadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes gameItemSlideIn {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .sidebar {
    width: 250px;
  }
}

@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    margin-top: 20px;
  }
  
  .game-vertical-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  
  .rank-number {
    align-self: center;
    width: 20px;
    height: 20px;
    font-size: 14px;
  }
  
  .game-vertical-name {
    font-size: 13px;
  }
}
</style>